package bookstudytest;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

/**
 * Created by swordbone on 2017/11/17.
 */
public class InnerClass {
    private int interval;
    private boolean beap;
    public InnerClass(int interval,boolean beap){
        this.interval=interval;
        this.beap=beap;
    }
    public static void main(String[] args){
        InnerClass innerClass=new InnerClass(12,true);

        innerClass.start();
        JOptionPane.showMessageDialog(null,"退群！");
        System.exit(0);
    }
    public void start(){
//比较正规的写法，内部类对象创建
        ActionListener actionListener=this.new Timerprinter();
//        匿名内部类
        ActionListener actionListener1=new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("do something!");
            }
        };
        Timer timer=new Timer(5000,actionListener);
        timer.start();

    }
    public class Timerprinter implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            Date date=new Date();
            System.out.println("大哥大嫂过年好！");
//            调用了InnerClass的变量
            if(InnerClass.this.beap) Toolkit.getDefaultToolkit().beep();
        }
    }

}
